from typing import Sequence

from fastapi import UploadFile
from fastapi.responses import FileResponse, StreamingResponse

from app.controllers.base_controller import BaseController
from app.crud.file_crud import FileCRUD
from app.models import File
from app.models.base import IdType
from app.schemas.file_schema import FileCreate, FileUpdate
from app.schemas.result_schema import ResultFormat, ResultModel


class FileController(BaseController[FileCRUD,File,FileCreate,FileUpdate]):
    async def upload_file(self,file: UploadFile) -> ResultModel[File]:
        result = await self.crud.upload_file(file=file)
        return ResultFormat.result_model(data=result)

    async def upload_files(self,files: Sequence[UploadFile]) -> ResultModel[Sequence[File]]:
        result = await self.crud.upload_files(files=files)
        return ResultFormat.result_list_model(data=result)

    async def download_file(self,id: IdType) -> FileResponse:
        return await self.crud.download_file(id=id)

    async def download_files(self,ids: Sequence[IdType]) -> StreamingResponse:
        return await self.crud.download_files(ids=ids)

